package com.store.controller;

import com.store.annotation.OperationLog;
import com.store.domain.R;
import com.store.domain.dto.UserDto;
import com.store.domain.entity.User;
import com.store.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yu
 * @date 2024/6/26
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;
    @OperationLog("查询个人信息")
    @GetMapping("getUserInfo")
    public R getUserInfo(){
        return userService.getUserInfo();
    }
    @OperationLog("用户信息分页")
    @GetMapping("getPageUser")
    public R getPageUser(@RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize,
                         UserDto userDto){
        return userService.getPageUser(pageNum, pageSize, userDto);
    }
    @OperationLog("修改用户状态")
    @PutMapping("updateUserStatus")
    public R updateUserStatus(@RequestBody UserDto userDto){
        return userService.updateUserStatus(userDto);
    }
    @OperationLog("删除用户")
    @DeleteMapping("deleteUser/{ids}")
    public R deleteUser(@PathVariable Integer[] ids){
        return userService.deleteUserByIds(ids);
    }

    @OperationLog("修改用户信息")
    @PutMapping("updateUserInfo")
    public R updateUserInfo(@RequestBody UserDto userDto){
        return userService.updateUserInfo(userDto);
    }
    @OperationLog("根据id查询用户信息")
    @GetMapping("getUserInfoById/{id}")
    public R getUserInfoById(@PathVariable Integer id){
        return userService.getUserInfoById(id);
    }
    @OperationLog("添加用户")
    @PostMapping("addUser")
    public R addUser(@RequestBody UserDto userDto){
        return userService.addUser(userDto);
    }

}
